import request from "@/utils/request";
import {baseURL} from "@/config/constant";

const baseUrl = "studentAwards/";

/**
 * 获取所有学生奖状信息信息
 * @param pagination
 * @param keyword
 * @returns {AxiosInstance}
 */
export function page(pagination, keyword) {
  return new request({
    url: `${baseUrl}list`,
    method: "GET",
    params: {...pagination, ...keyword}
  })
}

/**
 * 添加单个学生奖状信息
 * @returns {AxiosInstance}
 * @param data
 */
export function addStudentAwards(data) {
  return new request({
    url: `${baseUrl}`,
    method: "POST",
    data: data
  })
}

/**
 * 修改单个学生奖状信息
 * @returns {AxiosInstance}
 * @param data
 */
export function updateStudentAwards(data) {
  return new request({
    url: `${baseUrl}`,
    method: "PUT",
    data: data
  })
}

/**
 * 删除单个学生奖状信息
 * @returns {AxiosInstance}
 * @param id
 */
export function deleteStudentAwards(id) {
  return new request({
    url: `${baseUrl}?id=${id}`,
    method: "DELETE",
  })
}

/**
 * 删除多个学生奖状信息
 * @returns {AxiosInstance}
 * @param ids
 */
export function deleteMultipleStudentAwards(ids) {
  let filterIds = "?";
  ids.forEach(item => filterIds += `ids=${item}&`);
  filterIds = filterIds.substr(0, filterIds.length - 1);
  return new request({
    url: `${baseUrl}multiple${filterIds}`,
    method: "DELETE",
  })
}

/**
 * baseURL 服务器名称
 *
 * 删除文件
 */
export function removeFile(path) {
  path = path.slice(path.indexOf("/"), path.length);
  return new request({
    url: `${baseURL}file/?path=${path}`,
    method: "DELETE",
  })
}

